package 华为.text23_删除字符串中出现字符次数最少的字符;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        HashMap<Character, Integer> map = new HashMap<>();
        ArrayList<Character> list = new ArrayList<>();
        for (int i = 0; i < str.length(); i++) {
            Integer value = map.getOrDefault(str.charAt(i), 0);
            map.put(str.charAt(i),value+1);
            list.add(str.charAt(i));// 把字符串中的字符添加进这个集合中,保证有序性
        }

        Set<Character> keySet = map.keySet();
        int min=map.get(str.charAt(0));
        for (Character key : keySet) {
            min=Math.min(min,map.get(key));
        }

        for (Character key : keySet) {
            if (min==map.get(key)){      // 这个地方可以优化~
                //有几个字符删除几次~
                for (Integer i = 0; i < map.get(key); i++) {
                    list.remove(key);
                }
            }
        }

        StringBuilder stringBuilder = new StringBuilder();
        for (Character item : list) {
            stringBuilder.append(item);
        }
        System.out.println(stringBuilder.toString());
    }
}
